package com.ftg.learn.smhtml.controller;

import com.ftg.learn.smhtml.pojo.Dept;
import com.ftg.learn.smhtml.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/dept")

public class DemoController {


    @Autowired
    DeptService deptService;
    @GetMapping("/showDept")
    public Map<String,Object> showall(int page,int limit,String id){
        System.out.println(page+"||"+limit+"||"+id);
        Map<String,Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("count",deptService.getCount(id));
        map.put("msg", ".....");
        map.put("data", deptService.showAll(id,page,limit));
        return map;//转
    }

    @PostMapping("/addDept")
    public int addDept(Dept dept) {
        System.out.println(dept.getPid());
        return deptService.addDept(dept);
    }

    @DeleteMapping("/delDept/{ids}")
    //地址单一变量
    public boolean delDept(@PathVariable("ids") String[] ids) {
        System.out.println(Arrays.toString(ids));
        return deptService.delDept(ids);
    }

    @PutMapping("/findone/{id}")
    public Dept findOne(@PathVariable("id") String id) {
        return deptService.findOne(id);
    }

    @PostMapping("/updateDept")
    public int updateDept(Dept dept) {
        return deptService.updateDept(dept);
    }

}
